// Author: Domien Nowicki

#include "ResizeDialog.h"

ResizeDialog::ResizeDialog(QWidget *parent): QDialog(parent)
{
	setWindowTitle("Resize map");

	SetupDialog();

	setModal(true);
}

ResizeDialog::~ResizeDialog()
{
}

void ResizeDialog::SetupDialog()
{
    gridLayout = new QGridLayout(this);
    gridLayout->setSpacing(6);
    gridLayout->setMargin(9);
    vboxLayout = new QVBoxLayout();
    vboxLayout->setSpacing(6);
    vboxLayout->setMargin(0);

    labelResize = new QLabel(this);
    vboxLayout->addWidget(labelResize);

    hboxLayout = new QHBoxLayout();
    hboxLayout->setSpacing(6);
    hboxLayout->setMargin(0);

	// Width number selector spinbox
    widthSize = new QSpinBox(this);
    widthSize->setMinimum(0);
    widthSize->setValue(10);

    hboxLayout->addWidget(widthSize);

	// Add label "x"
    labelX = new QLabel(this);
    labelX->setAlignment(Qt::AlignCenter);

    hboxLayout->addWidget(labelX);

	// Height number selector spinbox
    heightSize = new QSpinBox(this);
    heightSize->setMinimum(0);
    heightSize->setValue(10);

    hboxLayout->addWidget(heightSize);


    vboxLayout->addLayout(hboxLayout);


	spacerItem = new QSpacerItem(40, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
	vboxLayout->addItem(spacerItem);


    gridLayout->addLayout(vboxLayout, 0, 0, 1, 1);


	// Add the [ok][cancel] buttons
    buttonBox = new QDialogButtonBox(this);
    buttonBox->setOrientation(Qt::Horizontal);
    buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);

    gridLayout->addWidget(buttonBox, 1, 0, 1, 1);


    QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
    QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
	QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(slotResize()));

    labelResize->setText("Resize map to:");
    labelX->setText("x");
}

void ResizeDialog::slotResize()
{
	unsigned int width = widthSize->value();
	unsigned int height = heightSize->value();

	// Tell listeners to resize map
	emit resize(width, height);
}